package com.usian.wemedia.controller.v1;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.usian.apis.wemedia.WmUserControllerApi;
import com.usian.model.media.pojos.WmUser;
import com.usian.wemedia.service.WmUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@RestController
@RequestMapping("/api/v1/user")
public class WmUserController  implements WmUserControllerApi {
    @Autowired
    private WmUserService userService;

    @PostMapping("/save")
    @Override
    public WmUser save(@RequestBody WmUser wmUser) {
        wmUser.setCreatedTime(new Date());
        userService.save(wmUser);
        return wmUser;
    }

    @GetMapping("/findByName/{name}")
    @Override
    public WmUser findByName(@PathVariable("name") String name) {
        return userService.getOne(Wrappers.<WmUser>lambdaQuery().eq(WmUser::getName, name));
    }
}
